<%--
  Created by IntelliJ IDEA.
  User: jshand
  Date: 2022-03-25
  Time: 8:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
<%--    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.min.js"></script>--%>
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script>

        function del(id){
            //http://127.0.0.1:8080/his/user/deleteById?id=12
            let success = confirm("是否删除???");
            if(success){
                let url = '${pageContext.request.contextPath}/user/deleteById?id='+id
                $.ajax(url,{
                    type:'GET',
                    dataType:'json',
                    /***
                     * {"success": true}
                     * @param data
                     */
                    success:function(data){
                        if(data && data.success){
                            alert("删除成功");
                            window.location ="/user/list"
                            window.location = window.location;//刷新页面
                        }else{
                            alert("删除失败");
                        }
                    }
                })





            }
        }

    </script>
</head>
<body>

<a href="${pageContext.request.contextPath}/user/toAdd">添加</a>
<h3>用户列表</h3>
<table width="100%" cellpadding="0" cellspacing="0" border="1">
    <tr>
        <th>userId</th>
        <th>username</th>
        <th>password</th>
        <th>realname</th>
        <th>telephone</th>
        <th>active</th>
        <th>createTime</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${userList}" var="user">
    <tr>
        <td>${user.userId}</td>
        <td>${user.username}</td>
        <td>${user.password}</td>
        <td>${user.realname}</td>
        <td>${user.telephone}</td>
        <td>
            <c:choose>
                <c:when test="${user.active == 1}">有效</c:when>
                <c:when test="${user.active != 1}">无效</c:when>
            </c:choose>
        </td>
        <td><fmt:formatDate value="${user.createTime}" pattern="yyyy年MM月dd日 HH:mm:ss"></fmt:formatDate>
                </td>
        <td>
            <a href="${pageContext.request.contextPath}/user/toEdit?id=${user.userId}" >更新</a>
            <button onclick="del(${user.userId})">删除</button>
        </td>
    </tr>
    </c:forEach>



</table>

</body>
</html>
